#define _CRT_SECURE_NO_WARNINGS	

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
typedef struct TreeNode TreeNode;

int postorder(TreeNode* root, int val)
{
    if (root == NULL)
        return 0;
    val = (val << 1) | root->val;
    if (root->left == NULL && root->right == NULL)
        return val;
    return postorder(root->left, val) + postorder(root->right, val);
}

int sumRootToLeaf(struct TreeNode* root)
{
    return postorder(root, 0);
}